const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
Page({
  data: {
    type:1,
    caseInfoId:'',
    detailForLawyer:{},
    route:''
  },
  onLoad(option) {
  console.log('option==>',option)
  this.setData({
    caseInfoId:option.id
  },()=>{
    this.getDetailForLawyer()
  })

  //获取页面
  var  route = getCurrentPages()[0].route
  route=route.slice(route.lastIndexOf('/')+1)
  this.setData({
    route
  })
  },
  onShow(){
   
   
  },
  cancel(){
  
    wx.showModal({
        title: '',
        content: "确定撤销该案源吗？",
        confirmColor:'#0557A8',
        cancelColor:'#C2C2C2',
        success (res) {
          if (res.confirm) {
          
            console.log('用户点击确定')
           
            
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
  },
  look(){
    wx.showModal({
        title: '不通过原因',
        content: "您好,我在网上申请再审,审核不通过的原因写的是:系统显示该案件无任何材料请上传材料才能通过您好,我在网上申请再审,审核不通过的原因写的是:系统显示该案件无任何材料请上传材料才能通过",
        confirmColor:'#0557A8',
        showCancel:false,
        cancelColor:'#C2C2C2',
        success (res) {
          if (res.confirm) {
            console.log('用户点击确定')
          
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
  },
  complete(){
    let that=this
    wx.showModal({
        title: '',
        content: "确定接单吗？",
        confirmColor:'#0557A8',
        cancelColor:'#C2C2C2',
        success (res) {
          if (res.confirm) {
            let caseInfoId=that.data.caseInfoId
            console.log('用户点击确定')
            // 接单
           
           if(caseInfoId||caseInfoId===0){
          
            Controller.acceptCaseInfo({caseInfoId}).then(res=>{
                wx.showToast({
                  title: '接单成功',
                  icon:'none'
                })
                that.getDetailForLawyer()
            })
           }else{
            wx.showToast({
              title: '接单失败',
              icon:'none'
            })
           }
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
  },
  //律师安源详情
  getDetailForLawyer(){
  let caseInfoId=this.data.caseInfoId
  Controller.detailForLawyer({caseInfoId}).then(res=>{
    let baseData=res.data.baseData
    // 类型
    if(baseData.categoryTitle){
      baseData.categoryTitle=baseData.categoryTitle.split(',')
    }else{
      baseData.categoryTitle=[]
    }
    
    
    if(baseData.otherVideoUrl){
      let videos=baseData.otherVideoUrl.split(',')
      baseData.otherVideoUrl=videos
    }else{
      baseData.otherVideoUrl=[]
    }
    if(baseData.otherImgUrls){
      let imgs=baseData.otherImgUrls.split(',')
      baseData.otherImgUrls=imgs
    }else{
      baseData.otherImgUrls=[]
    }

    this.setData({
      detailForLawyer:baseData
    })
    
    
  })
  },

  tabs(e){
    this.setData({
      type:e.currentTarget.dataset.type,
    })
  },
  golink(e){
    var url=e.currentTarget.dataset.url;
    if (!wx.getStorageSync('logintoken')) {
      app.goLogin(false)
      return
    }
    wx.navigateTo({
      url:e.currentTarget.dataset.url
    });
  },
  preview(event) {
    let currentUrl = event.currentTarget.dataset.src
    wx.previewImage({
      current: currentUrl, // 当前显示图片的http链接
      urls: this.data.detailForLawyer.otherImgUrls // 需要预览的图片http链接列表
    })
  },
  onShareAppMessage: function (e) {
    
  },
  onShareTimeline: function(res){
    
  },

})